package lp.xian.materials.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lp.xian.materials.vo.SaleoutVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.domain.Saleout;
import lp.xian.materials.service.ISaleoutService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售出库Controller
 *
 * @author ruoyi
 * @date 2023-08-25
 */
@RestController
@RequestMapping("/saleout/saleout")
public class SaleoutController extends BaseController
{
    @Autowired
    private ISaleoutService saleoutService;

    /**
     * 查询销售出库列表
     */
    @PreAuthorize("@ss.hasPermi('saleout:saleout:list')")
    @GetMapping("/list")
    public TableDataInfo list(Saleout saleout)
    {
        startPage();
        List<Saleout> list = saleoutService.selectSaleoutList(saleout);
        return getDataTable(list);
    }

    /**
     * 导出销售出库列表
     */
    @PreAuthorize("@ss.hasPermi('saleout:saleout:export')")
    @Log(title = "销售出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Saleout saleout)
    {
        List<Saleout> list = saleoutService.selectSaleoutList(saleout);
        ExcelUtil<Saleout> util = new ExcelUtil<Saleout>(Saleout.class);
        util.exportExcel(response, list, "销售出库数据");
    }

    /**
     * 获取销售出库详细信息
     */
    @PreAuthorize("@ss.hasPermi('saleout:saleout:query')")
    @GetMapping(value = "/{saleoutId}")
    public AjaxResult getInfo(@PathVariable("saleoutId") Integer saleoutId)
    {
        return success(saleoutService.selectSaleoutBySaleoutId(saleoutId));
    }

    /**
     * 新增销售出库
     */
    @PreAuthorize("@ss.hasPermi('saleout:saleout:add')")
    @Log(title = "销售出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Saleout saleout)
    {
        return toAjax(saleoutService.insertSaleout(saleout));
    }

    /**
     * 修改销售出库
     */
    @PreAuthorize("@ss.hasPermi('saleout:saleout:edit')")
    @Log(title = "销售出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Saleout saleout)
    {
        return toAjax(saleoutService.updateSaleout(saleout));
    }

    /**
     * 删除销售出库
     */
    @PreAuthorize("@ss.hasPermi('saleout:saleout:remove')")
    @Log(title = "销售出库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{saleoutIds}")
    public AjaxResult remove(@PathVariable Integer[] saleoutIds)
    {
        return toAjax(saleoutService.deleteSaleoutBySaleoutIds(saleoutIds));
    }

    // 销售出库审核
    @PreAuthorize("@ss.hasPermi('saleout:saleout:audit')")
    @Log(title = "销售出库",businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody SaleoutVo saleoutVo){
        return toAjax(saleoutService.auditSaleout(saleoutVo));
    }
}
